package com.letv.whatslive.model.convert;

import com.letv.whatslive.model.Start_ImageSrc;
import com.letv.whatslive.model.utils.ObjUtils;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

//2015.11.4

/**
 * Created by shenyue on 2015/11/4.
 */
public class Start_ImageSrcConvert {
    public static DBObject castStart_ImageSrcToDBObject(Start_ImageSrc start_ImageSrc) {
        DBObject dbo = new BasicDBObject();
        if (start_ImageSrc.getId() != null) {
            dbo.put("_id", start_ImageSrc.getId());
        }
        dbo.put("picType", ObjUtils.toInteger(start_ImageSrc.getPicType(), 0));
        //dbo.put("picCode", ObjUtils.toString(start_ImageSrc.getPicCode(), ""));
        dbo.put("picName", ObjUtils.toString(start_ImageSrc.getPicName(), ""));
        dbo.put("picSpec", ObjUtils.toString(start_ImageSrc.getPicSpec(), ""));
        dbo.put("picUrl", ObjUtils.toString(start_ImageSrc.getPicUrl(), ""));
        dbo.put("adUrl", ObjUtils.toString(start_ImageSrc.getAdUrl(), ""));
        dbo.put("createTime", ObjUtils.toLong(start_ImageSrc.getCreateTime(), 0l));
        dbo.put("updateTime", ObjUtils.toLong(start_ImageSrc.getUpdateTime(), 0l));
        dbo.put("startTime", ObjUtils.toLong(start_ImageSrc.getStartTime(), 0l));
        dbo.put("endTime", ObjUtils.toLong(start_ImageSrc.getEndTime(), 0l));
        dbo.put("showTime", ObjUtils.toLong(start_ImageSrc.getShowTime(), 0l));
        dbo.put("isOpen", ObjUtils.toInteger(start_ImageSrc.getIsOpen(), 0));
        dbo.put("phoneType", ObjUtils.toInteger(start_ImageSrc.getPhoneType(), 0));
        dbo.put("type", ObjUtils.toInteger(start_ImageSrc.getType(), 0));
        if(null!=start_ImageSrc.getBusiId()){
            dbo.put("busiId", ObjUtils.toString(start_ImageSrc.getBusiId()));
        }

        return dbo;


//        DBObject dbo = new BasicDBObject();
//        if (device.getId() != null) {
//            dbo.put("_id", device.getId());
//        }
//        dbo.put("platformId",device.getPlatformId());
//        dbo.put("sysVer", device.getSysVer());
//        dbo.put("model", device.getModel());
//        dbo.put("appVer", device.getAppVer());
//        dbo.put("corporationId", device.getCorporationId());
//        dbo.put("channelId", device.getChannelId());
//        return dbo;
    }

    public static Start_ImageSrc castDBObjectToStart_ImageSrc(DBObject dbObject) {
        Start_ImageSrc start_ImageSrc = new Start_ImageSrc();
        if (dbObject != null) {
            start_ImageSrc.setId(ObjUtils.toLong(dbObject.get("_id")));
            start_ImageSrc.setPicType(ObjUtils.toInteger(dbObject.get("picType")));
            //start_ImageSrc.setPicCode(ObjUtils.toString(dbObject.get("picCode")));
            start_ImageSrc.setPicName(ObjUtils.toString(dbObject.get("picName")));
            start_ImageSrc.setPicSpec(ObjUtils.toString(dbObject.get("picSpec")));
            start_ImageSrc.setPicUrl(ObjUtils.toString(dbObject.get("picUrl")));
            start_ImageSrc.setAdUrl(ObjUtils.toString(dbObject.get("adUrl")));
            start_ImageSrc.setCreateTime(ObjUtils.toLong(dbObject.get("createTime")));
            start_ImageSrc.setUpdateTime(ObjUtils.toLong(dbObject.get("updateTime")));
            start_ImageSrc.setStartTime(ObjUtils.toLong(dbObject.get("startTime")));
            start_ImageSrc.setEndTime(ObjUtils.toLong(dbObject.get("endTime")));
            start_ImageSrc.setShowTime(ObjUtils.toLong(dbObject.get("showTime")));
            start_ImageSrc.setIsOpen(ObjUtils.toInteger(dbObject.get("isOpen")));
            start_ImageSrc.setPhoneType(ObjUtils.toInteger(dbObject.get("phoneType")));
            start_ImageSrc.setType(ObjUtils.toInteger(dbObject.get("type"), 0));
            start_ImageSrc.setBusiId(ObjUtils.toString(dbObject.get("busiId")));
        }

        return start_ImageSrc;
    }
}
